﻿using EPE.BLL;
using EPE.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EPE.WPF
{
    /// <summary>
    /// UCProject.xaml 的交互逻辑
    /// </summary>
    public partial class UCProjectList : UserControl
    {
        public UCProjectList()
        {
            InitializeComponent();
            BindData();
        }

        CLoginUser userinfo = new CLoginUser();
        public UCProjectList(CLoginUser pargUserinfo)
        {
            InitializeComponent();
            userinfo = pargUserinfo;
            BindData();
            
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var drv = (DataRowView)this.dgList.SelectedItem;
                int iId = Convert.ToInt32(drv["projectid"]);
                ProjectEditForm edit = new ProjectEditForm(userinfo);
                edit.ShowInfo(iId);
                edit.ShowDialog();
                BindData();
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }

        private void btnDel_Click(object sender, RoutedEventArgs e)
        {
            //if (MessageBoxResult.OK == MessageBox.Show("是否删除数据！", "系统信息", MessageBoxButton.OKCancel, MessageBoxImage.Question))
            //{
            //    string idlist = "";

            //    var drv = (System.Data.DataRowView)this.dgCard.SelectedItem;
            //    idlist = drv["Id"].ToString();

            //    //VMS.BLL.tbl_departmentinfo bll = new VMS.BLL.tbl_departmentinfo();
            //    //bll.DeleteList(idlist);
            //    //BindData();
            //}

        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            BindData();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            ProjectAddForm frmPj = new ProjectAddForm(userinfo);
            frmPj.ShowDialog();

            BindData();
        }


        public void BindData()
        {


            DataSet ds = new DataSet();



            ShopsProject bll = new ShopsProject();


            ds = bll.GetListByPage(this.txtProjectName.Text,userinfo.CompanyId.ToString(), "projectname", this.pagectrl.PageIndex, this.pagectrl.PageSize);

            DataTable dt = ds.Tables[0];

            this.dgList.DataContext = dt;
            this.pagectrl.TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
        }

        private void pagectrl_PagerIndexChanged(object sender, EventArgs e)
        {
            BindData();
        }


    }
}
